export KUBECONFIG={{ KUBERNETES_CONFIG_PATH }}/{{ KUBECTL_CONFIG_FILE }}
kubectl get clusterrolebinding | grep kubelet-bootstrap
if [ $? == 1 ] 
then
  kubectl create clusterrolebinding kubelet-bootstrap --clusterrole=system:node-bootstrapper --user=kubelet-bootstrap
  if [ $? == 0 ]
  then
    BOOTSTRAP_TOKEN=`awk -F "," '{print $1}' {{ PKI_PATH }}/token.csv`
    kubectl config set-cluster kubernetes --certificate-authority={{ PKI_PATH }}/ca.pem --embed-certs=true --server=https://{{ VIP }}:{{ HAPROXY_KUB_API_PORT }} --kubeconfig={{ KUBERNETES_CONFIG_PATH }}/kubelet-bootstrap.kubeconfig
    kubectl config set-credentials kubelet-bootstrap --token=${BOOTSTRAP_TOKEN} --kubeconfig={{ KUBERNETES_CONFIG_PATH }}/kubelet-bootstrap.kubeconfig
    kubectl config set-context default --cluster=kubernetes --user=kubelet-bootstrap --kubeconfig={{ KUBERNETES_CONFIG_PATH }}/kubelet-bootstrap.kubeconfig
    kubectl config use-context default --kubeconfig={{ KUBERNETES_CONFIG_PATH }}/kubelet-bootstrap.kubeconfig
  fi
fi
